package com.itheima.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.mapper.CmsPrefrenceAreaProductRelationMapper;
import com.itheima.pojo.CmsPrefrenceAreaProductRelation;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class CmsPrefrenceAreaProductRelationImpl implements CmsPrefrenceAreaProductRelationApi {

    @Autowired
    private CmsPrefrenceAreaProductRelationMapper mapper;

    /**
     *商品添加
     */
    @Override
    public void save(List<CmsPrefrenceAreaProductRelation> prefrenceAreaProductRelationList,Long productId) {
        for (CmsPrefrenceAreaProductRelation cmsPrefrenceAreaProductRelation : prefrenceAreaProductRelationList) {
            cmsPrefrenceAreaProductRelation.setProductId(productId);
            mapper.insert(cmsPrefrenceAreaProductRelation);
        }
    }

    /**
     *根据商品id获取商品编辑信息
     */
    @Override
    public List<CmsPrefrenceAreaProductRelation> updateInfo(Integer productId) {
        LambdaQueryWrapper<CmsPrefrenceAreaProductRelation> lqw = new LambdaQueryWrapper<>();
        lqw.eq(CmsPrefrenceAreaProductRelation::getProductId,productId);
        List<CmsPrefrenceAreaProductRelation> cmsPrefrenceAreaProductRelations = mapper.selectList(lqw);
        return cmsPrefrenceAreaProductRelations;
    }

    /**
     * 更新商品
     */
    @Override
    public void updateProduct(List<CmsPrefrenceAreaProductRelation> prefrenceAreaProductRelationList, Long productId) {
        for (CmsPrefrenceAreaProductRelation cmsPrefrenceAreaProductRelation : prefrenceAreaProductRelationList) {
            cmsPrefrenceAreaProductRelation.setProductId(productId);
            mapper.updateById(cmsPrefrenceAreaProductRelation);
        }
    }

}
